package com.ocean.queue;

public class CircularQueue {
    private String[] items;
    private int n;
    private int tail = 0;
    private int head = 0;

    public CircularQueue(int n) {
        this.items = new String[n];
        this.n = n;
    }


    public boolean enqueue(String ele) {
        if ((tail + 1) % n == head) {
            return false;
        }
        items[tail] = ele;
        tail = (tail + 1) % n;
        return true;
    }

    public String dequeue() {
        // 判断是否为空
        if (tail == head) {
            return null;
        }
        String ret = items[head];
        head = (head + 1) % n;
        return ret;
    }
}
